package com.ruoyi.shopping.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shopping.domain.MallRegions;
import com.ruoyi.shopping.service.IMallRegionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地州管理Controller
 * 
 * @author cws
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/shopping/regions")
public class MallRegionsController extends BaseController
{
    @Autowired
    private IMallRegionsService mallRegionsService;

    /**
     * 查询地州管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallRegions mallRegions)
    {
        startPage();
        List<MallRegions> list = mallRegionsService.selectMallRegionsList(mallRegions);
        return getDataTable(list);
    }

    /**
     * 导出地州管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:export')")
    @Log(title = "地州管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallRegions mallRegions)
    {
        List<MallRegions> list = mallRegionsService.selectMallRegionsList(mallRegions);
        ExcelUtil<MallRegions> util = new ExcelUtil<MallRegions>(MallRegions.class);
        util.exportExcel(response, list, "地州管理数据");
    }

    /**
     * 获取地州管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mallRegionsService.selectMallRegionsById(id));
    }

    /**
     * 新增地州管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:add')")
    @Log(title = "地州管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallRegions mallRegions)
    {
        return toAjax(mallRegionsService.insertMallRegions(mallRegions));
    }

    /**
     * 修改地州管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:edit')")
    @Log(title = "地州管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallRegions mallRegions)
    {
        return toAjax(mallRegionsService.updateMallRegions(mallRegions));
    }

    /**
     * 删除地州管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:regions:remove')")
    @Log(title = "地州管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallRegionsService.deleteMallRegionsByIds(ids));
    }


    /**
     * 获取所有地州名称
     */
    @GetMapping("/getAllRegionsName")
    public AjaxResult getAllRegionsName(){
        List<MallRegions>  reginsNames=mallRegionsService.getAllRegionsName();
        return success(reginsNames);
    }


}
